package com.study.lxy.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class HelloInvocationHandler implements InvocationHandler {

    private Object target;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("hello before function invoke");
        Object result = method.invoke(target, args);
        System.out.println("hello after function invoke");
        return result;
    }

    public HelloInvocationHandler(Object target){
        this.target = target;
    }

    public static Object bind(Object target){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new HelloInvocationHandler(target));
    }


}
